import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import './assets/css/style.less'
import global from  './assets/js/global'
import './assets/font/iconfont.css'
import elementUi from 'element-ui'
import Vuetify from 'vuetify'
import vuetify from '@/plugins/vuetify'
import captcha from 'vue-social-captcha'
import 'material-design-icons-iconfont/dist/material-design-icons.css'
import '@mdi/font/css/materialdesignicons.css'
import 'element-ui/lib/theme-chalk/index.css'
import SlideVerify from 'vue-monoplasty-slide-verify'
import VueParticles from 'vue-particles'
import axios from 'axios'
import vueaxios from 'vue-axios'
require('./Mock')
import {parseTime} from './utils'
import { mdiAccount } from '@mdi/js'

Vue.prototype.GLOBAL = global

Vue.use(elementUi)
Vue.use(vueaxios, axios)
Vue.use(SlideVerify)
Vue.use(VueParticles)
Vue.use(Vuetify)
Vue.use(captcha)


Vue.config.productionTip = false
Vue.filter('parseTime', (v) => parseTime(v,'{y}-{m}-{d}'))
new Vue({
  router,
  store,
	vuetify,
	mdiAccount,
  render: h => h(App)
}).$mount('#app')


/**
 * axios全局请求拦截器,拦截所有axios请求
 * 每次发送axios请求携带Token请求头,携带访问令牌请求后端
 */
axios.interceptors.request.use(
	config => {
		if (localStorage.getItem('accessToken')) {
			config.headers.Authorization = 'Bearer ' + localStorage.getItem('accessToken');
		}
		return config;
	},
	error => {
		return Promise.reject(error);
	});


/**
 * axios全局响应拦截器,拦截所有axios响应
 * 每次响应判断状态码,若为401给出友好提示,提示未登录
 */
axios.interceptors.response.use(
	response => {
		return response;
	},
	error => {
		if(error.response.status === 401) {
			Vue.prototype.$message({
				message: '请先登录,再进行相关操作哦~',
				type: 'warning',
				center: true
			})
			return;
		}
		return Promise.reject(error);
	});
